#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>

unsigned long int msec = 0, msec_start = 0, msec_end = 0;

void sigint(int signum)
{
        printf("\r%ud%02uh%02u:%02u:%03u", (msec / 1000 / 3600 / 24), (msec / 1000 / 3600) % 24, (msec / 1000 / 60) % 60, msec / 1000 % 60, msec++ % 1000);
        fflush(stdout);
}

int main()
{
        signal(SIGINT, sigint);

        struct timeval t_start = {}, t_end = {};
        gettimeofday(&t_start, NULL);
        msec_start = t_start.tv_sec * 1000 + t_start.tv_usec / 1000;

        while (1)
        {
                usleep(10000);
                gettimeofday(&t_end, NULL);
                msec_end = t_end.tv_sec * 1000 + t_end.tv_usec / 1000;
                msec = msec_end - msec_start;
                //printf("%u %u, %u\n", msec_end, msec_start, msec);
                printf("\r%ud%02uh%02u:%02u:%03u", (msec / 1000 / 3600 / 24), (msec / 1000 / 3600) % 24, (msec / 1000 / 60) % 60, msec / 1000 % 60, msec++ % 1000);
                fflush(stdout);
        };
}

